//对 spdlog 做二次封装，满足我们的使用需求

#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include<spdlog/async.h>
#include <spdlog/sinks/basic_file_sink.h>
#include<string>

std::shared_ptr<spdlog::logger> g_logger;

//初始化
void init_mylogger(bool mode, const std::string logger_name, const std::string logfile_path, uint8_t level, bool truncate)
{
    //mode == false 表示调试模式；反之 发布模式
    if (mode)
    {
        spdlog::init_thread_pool(4096, 1);
        g_logger = spdlog::basic_logger_mt<spdlog::async_factory>(logger_name, logfile_path, truncate);
    }
    else
    {
        g_logger = spdlog::stderr_color_mt(logger_name);
    }
    g_logger->set_level((spdlog::level::level_enum)level);
    g_logger->flush_on(spdlog::level::err);
    g_logger->flush_on(spdlog::level::critical);

    g_logger->set_pattern("[%n][%Y/%m%d %H:%M:%S][%-8l]: %v");
}

//定义宏函数
#define LOG_TRACE(format, ...) g_logger->trace(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
#define LOG_DEBUG(format, ...) g_logger->debug(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
#define LOG_INFO(format, ...) g_logger->info(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
#define LOG_WARN(format, ...) g_logger->warn(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
#define LOG_ERROR(format, ...) g_logger->error(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
#define LOG_FATAL(format, ...) g_logger->critical(std::string("[{}:{}]") + format, __FILE__, __LINE__, ##__VA_ARGS__);
